package zwylinkedlist;

import java.util.LinkedList;
import java.util.NoSuchElementException;

import org.junit.Test;

import bean.UserBean;

public class LinkedList02Test {
	
	/**
	* @return the first element in this list
	* @throws NoSuchElementException if this list is empty
	* @title: getFirstTest 
	* @Author: zhaoweiyong
	* @Date: 2017年7月7日下午3:11:28
	 */
	@Test
	public void getFirstTest(){
		
		LinkedList<String> linkedList = new LinkedList<String>();
		try {
			//获取First其实是返回LinkedList的Node first 的字段值
			//这个阶段first = null;
			//所以throw NoSuchElementException
			//只有执行过添加才会有first、last
			linkedList.getFirst();
		} catch (Exception e) {
//			e.printStackTrace();
		}
		//linkLast
		linkedList.add("hello");
		linkedList.add("world");
		String first = linkedList.getFirst();
		System.out.println(first);
		String last = linkedList.getLast();
		System.out.println(last);
		linkedList.removeFirst();
		System.out.println("删除后："+linkedList);
		linkedList.removeLast();
		System.out.println("删除后："+linkedList);
	}
	
	@Test
	public void testBakObject(){
		UserBean bean = new UserBean("lisy", 23);
		UserBean bakBean = bean;
		bean = null;
		System.out.println(bakBean);
	}
	
}
